package cn.com.fuhuitong.main.home.adapter

import android.annotation.SuppressLint
import android.content.Context
import android.view.View
import cn.com.fuhuitong.app.BASE_HTTP_URL
import cn.com.fuhuitong.base.BaseDelegateAdapter
import cn.com.fuhuitong.main.home.entity.FlagshipListEntity
import com.alibaba.android.vlayout.LayoutHelper
import com.bumptech.glide.Glide
import cn.com.fuhuitong.R
import cn.com.fuhuitong.app.getImageUrl
import cn.com.fuhuitong.utils.WebViewUtils
import kotlinx.android.synthetic.main.item_flagship_details.view.*
import kotlinx.android.synthetic.main.item_flagship_list.view.*

enum class FVT(value: Int) {
    FLAGSHIP_LIST(1),
    FLAGSHIP_CONTENT(2)
}

class FlagshipListAdapter(
    private val mContext: Context, private val mHelper: LayoutHelper
) : BaseDelegateAdapter<FlagshipListEntity>(
    mContext = mContext,
    mHelper = mHelper,
    mLayoutId = R.layout.item_flagship_list,
    mItemViewType = FVT.FLAGSHIP_LIST.ordinal
) {
    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(itemView: View, position: Int, itemData: FlagshipListEntity) {
        super.onBindViewHolder(itemView, position, itemData)

        itemView.text_flagship_list_name.text = itemData.name
        itemView.text_flagship_list_address.text = itemData.address
        itemView.text_flagship_list_mobile.text = "联系电话：${itemData.mobile ?: ""}"
        itemView.text_flagship_list_distance.text = itemData.distance.toString()

        Glide.with(itemView).load(getImageUrl(itemData.image))
            .into(itemView.image_flagship_list_icon)
    }
}

class FlagshipDetailsAdapter(
    private val mContext: Context, private val mHelper: LayoutHelper
) : BaseDelegateAdapter<String>(
    mContext = mContext,
    mHelper = mHelper,
    mLayoutId = R.layout.item_flagship_details,
    mItemViewType = FVT.FLAGSHIP_CONTENT.ordinal
) {
    override fun onBindViewHolder(itemView: View, position: Int, itemData: String) {
        super.onBindViewHolder(itemView, position, itemData)

        WebViewUtils.loadFullScreenHtml(itemView.web_flagship_content, itemData)
    }
}